<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        let cites = [
            { py: 'beijing', name: '北京' },
            { py: 'alishan', name: '阿里山' },
            { py: 'beidaihe', name: '北戴河' },
            { py: 'hunan', name: '湖南' },
            { py: 'guangdong', name: '广东' },
            { py: 'guangxi', name: '广西' },
            { py: 'hubei', name: '湖北' },
            { py: 'shandong', name: '山东' },
            { py: 'shanxi', name: '山西' },
            { py: 'shanghai', name: '上海' },
            { py: 'shanxi', name: '陕西' },
            { py: 'fujian', name: '福建' },
            { py: 'henan', name: '河南' },
            { py: 'yunnan', name: '云南' }
        ]
        let obj = {};
        for (let i = 0; i < str.length; i++) {
            obj[str[i]] = [];
        }
        cites.forEach(function (item) {
            // for (var key in obj) {
            //     if (item.py[0].toUpperCase() == key) {
            //         obj[key].push(item);
            //     }
            // }
            // for (var key in obj) {
            //     item.py[0].toUpperCase() == key ? obj[key].push(item) : '';
            // }
            obj[item.py[0].toUpperCase()].push(item);
        })
        console.log(obj);
    </script>
</body>

</html>